package com.huxt.Recursion.lookou;

class Solution3 {

    public ListNode removeElements(ListNode head, int val) {
        ListNode dummyHead = new ListNode(-6);
        dummyHead.next = head;

        ListNode prev = dummyHead;
        while(prev.next != null){
            if(prev.next.val == val)
                prev.next = prev.next.next;
            else
                prev = prev.next;
        }

        return dummyHead.next;
    }

    public static void main(String[] args) {
        ListNode head = new ListNode(2);
        ListNode head1 = new ListNode(4);
        ListNode head2 = new ListNode(4);
        ListNode head3 = new ListNode(4);
        head.next = head1;
        head1.next = head2;
        head2.next = head3;
        Solution3 solution3 = new Solution3();
        solution3.removeElements(head,4);
        System.out.println(head);

    }

}